<template>
    <div>
        <city-header></city-header>
        <cesium-containerc :newArr5="newArr5" :newArr7="newArr7"></cesium-containerc>
        <div class="cityLeftContent">
            <cityLeft-contentOne 
            :QXZS="QXZS"
            :weatherList="weatherList" :CityEPAdata="CityEPAdata" :AllCityAqi="AllCityAqi"></cityLeft-contentOne>
            <cityLeft-contentTwo></cityLeft-contentTwo>
            <cityLeft-contentThree :CityEPAdata="CityEPAdata" :AllCityAqi="AllCityAqi"></cityLeft-contentThree>   
        </div>
        <right-tool></right-tool>
        <common-bottom></common-bottom>
        <city-centerContent :QXZs24h="QXZs24h" :QXZs7day="QXZs7day"></city-centerContent>
        <common-legend></common-legend>
        <!-- <city-stationCount :getStationCountData="getStationCountData" :StationQXDJCounts="StationQXDJCounts" :CityEPAdata="CityEPAdata"></city-stationCount> -->
        <!-- <common-controlBtn></common-controlBtn> -->
    </div>
</template>
<script>
import CesiumContainerc from '../cesium/CesiumContainerc'
import CityHeader from './components/CityHeader'
import RightTool from '../commons/RightTool'
import CityLeftContentOne from './components/CityLeftContentOne'
import CityLeftContentTwo from './components/CityLeftContentTwo'
import CityLeftContentThree from './components/CityLeftContentThree'
import CityCenterContent    from './components/CityCenterContent'
import CommonBottom from '../commons/CommonBottom'
import CommonLegend from '../commons/CommonLegend'
import CityStationCount from './components/CityStationCount'
// import CommonControlBtn from '../commons/CommonControlBtn'
//import serveUrl from './serve.js'
import axios from 'axios'
export default {
    name: 'City',
    data(){
        return{
           timer:null,
           weatherList: null,
           city_code: '',
           timer: null,
           CityEPAdata:{},       
           AllCityAqi:{},
           QXZS:{},
           QXZs24h:[],
           QXZs7day:[],
           newArr5:[],
           newArr7:[],
           dingwei:'dw',
           cityCode:[{
                "id": 382,
                "city_code": "101210101",
                "city_name": "杭州"
            },
            {
                "id": 383,
                "city_code": "101210201",
                "city_name": "湖州"
            },
            {
                "id": 384,
                "city_code": "101210301",
                "city_name": "嘉兴"
            },
            {
                "id": 385,
                "city_code": "101210901",
                "city_name": "金华"
            },
            {
                "id": 386,
                "city_code": "101210801",
                "city_name": "丽水"
            },
            {
                "id": 387,
                "city_code": "101210401",
                "city_name": "宁波"
            },
            {
                "id": 388,
                "city_code": "101210501",
                "city_name": "绍兴"
            },
            {
                "id": 389,
                "city_code": "101210601",
                "city_name": "台州"
            },
            {
                "id": 390,
                "city_code": "101210701",
                "city_name": "温州"
            },
            {
                "id": 391,
                "city_code": "101211101",
                "city_name": "舟山"
            },
            {
                "id": 392,
                "city_code": "101211001",
                "city_name": "衢州" 
            }]
        }
    },
    components: {
        CesiumContainerc,
        CityHeader,
        RightTool,
        CityLeftContentOne,
        CityLeftContentTwo,
        CityLeftContentThree,
        CommonBottom,
        CommonLegend,
        CityCenterContent,
        CityStationCount
    },
    created(){
        this.$store.commit("changeForq",1)
    },
    watch:{
        
    },
    mounted(){
        for(let i = 0;i<this.cityCode.length;i++){
            // 对比两个数，先看两个值的长度是否一样 .length
            if( this.cityCode[i].city_name == this.$route.params.name.trim() ){
                this.city_code = this.cityCode[i].city_code;
            }
        }
        this.$comjs.onCenter(119.906064,29.573401,961893.0);
        setTimeout(()=>{
            this.getWeather();
        },200)
        this.getCityWData();  
        var date = new Date();//现在时刻
        var dateIntegralPoint = new Date();//用户登录时刻的下一个整点，也可以设置成某一个固定时刻
        dateIntegralPoint.setHours(date.getHours()+1);//小时数增加1
        dateIntegralPoint.setMinutes(10);
        dateIntegralPoint.setSeconds(0);
        console.log(dateIntegralPoint);
        console.log(dateIntegralPoint-date);
        console.log((dateIntegralPoint-date)/60000);
        setTimeout(()=>{this.andUpdata()},dateIntegralPoint-date);//用户登录后的下一个整点执行。
    },
   beforeDestroy(){
        if(this.timer){
          clearInterval(this.timer)
        }
    },
    methods: {
        getWeather(){
            axios.get('/api'+ this.city_code).then(
                this.getWeatherInfo
            )
        },
        getWeatherInfo(res){
           setTimeout(()=>{
                 this.weatherList = res.data;
            },300)
        },
        getCityWData(){   
            if(this.$comjs.isOnline){
                axios.get('/apis/api/QX/GetQXCityInfo?city='+this.$store.state.headerCity).then(
                    this.getCityWDataInfo
                )
            }else{
                axios.get(this.$comjs.qhzsCity).then(
                    this.getCityWDataInfo
                )
            }     
            
            
        },
        getCityWDataInfo(res){  
            if(res.data.CityEPAdata){
                this.CityEPAdata=res.data.CityEPAdata;
            }
            if(res.data.AllCityAqi){
                this.AllCityAqi=res.data.AllCityAqi;     
            }
            if(res.data.QXZs24h){
                this.QXZs24h=res.data.QXZs24h; 
            }
            if(res.data.QXZs7day){
                this.QXZs7day=res.data.QXZs7day; 
            }
            if(res.data.QXZS){
                this.QXZS =  res.data.QXZS; 
                if(this.dingwei=='dw'){
                    this.$comjs.onCenter(res.data.QXZS.Lon,res.data.QXZS.Lat,360000.0);
                }
                this.$store.commit('changeCityY',res.data.QXZS.Lat)
            }
            if(res.data.Regions){
                this.$store.commit("changeCounty",res.data.Regions)
            }
            if(res.data.StationQXZs){
                this.newArr5 = res.data.StationQXZs;
            }
            if(res.data.CountryQXZs){
                this.newArr7 = res.data.CountryQXZs;
            }             
            
            
            
           
            
           
                 
        },
        andUpdata(){
          this.dingwei='bdw';
          this.getCityWData()//在整点执行的函数，在每个整点都调用该函数
          this.timer =  setInterval(()=>{this.getCityWData()},60*60*1000);//一个小时执行一次，那么下一个整点，下下一个整点都会执行
        }
    }
}
</script>
<style scoped>
    .cityLeftContent{
        position: absolute;
        left: 0;
        top: 6.57vh;
        z-index: 2;
        width: 4.02rem;
        height: calc(100% - 12.3vh); 
        /* height: 87.7vh; */
        /* overflow: hidden */
    }
</style>

